﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLLottery
{
    public partial class NewsItem : UserControl
    {
        public NewsItem()
        {
            InitializeComponent();
        }
        public void SetNewsString(string strNews)
        {
            if (!string.IsNullOrEmpty(strNews))
            {
                try
                {
                    string[] strArray = strNews.Split(new char[] { '|' });
                    if (strArray.Length < 2)
                    {
                        this.SetTextNewsString(strNews);
                    }
                    else
                    {
                        string str = strArray[0];
                        if (str == null)
                        {
                            goto Label_0097;
                        }
                        if (!(str == "1"))
                        {
                            if (str == "2")
                            {
                                goto Label_006F;
                            }
                            goto Label_0097;
                        }
                        this.SetSysMsgString(strArray[1]);
                    }
                    return;
                Label_006F:
                    if (strArray.Length < 3)
                    {
                        this.SetTextNewsString(strArray[1]);
                    }
                    else
                    {
                        this.SetUrlNewsString(strArray[1], strArray[2]);
                    }
                    return;
                Label_0097:
                    this.SetTextNewsString(strArray[1]);
                }
                catch
                {
                    this.SetTextNewsString(strNews);
                }
            }
        }

        private void SetSysMsgString(string msg)
        {
            this.imgType1.Visibility=Visibility.Visible;
            TextBlock block = new TextBlock();
            block.TextWrapping= TextWrapping.Wrap;
            block.Text=msg;
            block.Foreground=new SolidColorBrush(Color.FromArgb(0xff, 0, 0xff, 0));
            this.contentGrid.Children.Clear();
            this.contentGrid.Children.Add(block);
        }

        private void SetTextNewsString(string strNews)
        {
            this.imgType0.Visibility = Visibility.Visible;
            TextBlock block = new TextBlock();
            block.TextWrapping = TextWrapping.Wrap;
            block.Text=strNews;
            block.Foreground=new SolidColorBrush(Colors.White);
            this.contentGrid.Children.Clear();
            this.contentGrid.Children.Add(block);
        }

        private void SetUrlNewsString(string strNews, string url)
        {
            this.imgType2.Visibility = Visibility.Visible;
            HyperlinkButton button = new HyperlinkButton();
            TextBlock block = new TextBlock();
            block.TextWrapping = TextWrapping.Wrap;
            block.Text=strNews;
            block.Foreground=new SolidColorBrush(Colors.Yellow);
            block.TextDecorations=TextDecorations.Underline;
            button.Content=block;
            button.NavigateUri=new Uri(url);
            button.TargetName="_blank";
            this.contentGrid.Children.Clear();
            this.contentGrid.Children.Add(button);
        }
    }
}
